package com.zyt.controller;
import com.zyt.entity.Brand;
import com.zyt.service.BrandService;
import com.zyt.service.PhoneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class BrandController {
    @Autowired
    private BrandService brandService;
    @Autowired
    private PhoneService phoneService;
    @RequestMapping("/selectAllBrand")
    public String selectAllBrand(Model model){
        List<Brand> brands = brandService.selectAllBrand();
        model.addAttribute("brands",brands);
        return "/addon.jsp";
    }
    @RequestMapping("/selectAllBrandCou")
    public String selectAllBrandcou(Model model){
        List<Brand> brands = brandService.selectAllBrandcou();
        model.addAttribute("brands",brands);
        return "/brand-list.jsp";
    }
    @RequestMapping("/insertBrand")
    public String insertBrand(Brand brand,Model model){
        brandService.insertBrand(brand);
        return "/selectAllBrandCou.do";
    }
    @RequestMapping("/deleteByBrand")
    public String deleteByBrand(Integer id){
        brandService.deleteByBrand(id);
        phoneService.deleteBybId(id);
        return "/selectAllBrandCou.do";
    }
}
